<template>
	<view class="feedback-container">
		<!-- 主要内容 -->
		<view class="main-content">
			<!-- 反馈类型选择 -->
			<view class="section">
				<text class="section-title">反馈类型</text>
				<view class="type-grid">
					<view 
						v-for="(type, index) in feedbackTypes" 
						:key="index"
						class="type-item"
						:class="{ active: selectedType === index }"
						@click="selectType(index)"
					>
						<uni-icons :type="type.icon" size="20" :color="selectedType === index ? '#8B4513' : '#666'"></uni-icons>
						<text class="type-text">{{ type.name }}</text>
					</view>
				</view>
			</view>

			<!-- 问题描述 -->
			<view class="section">
				<text class="section-title">问题描述</text>
				<view class="input-card">
					<textarea 
						class="description-input"
						v-model="description"
						placeholder="请详细描述您遇到的问题或建议..."
						maxlength="500"
						:show-confirm-bar="false"
					></textarea>
					<text class="char-count">{{ description.length }}/500</text>
				</view>
			</view>

			<!-- 联系方式 -->
			<view class="section">
				<text class="section-title">联系方式（选填）</text>
				<view class="input-card">
					<input 
						class="contact-input"
						v-model="contact"
						placeholder="联系方式，方便我们回复您"
					/>
				</view>
			</view>

			<!-- 提交按钮 -->
			<view class="submit-section">
				<button 
					class="submit-btn"
					:class="{ disabled: !canSubmit }"
					:disabled="!canSubmit"
					@click="submitFeedback"
				>
					<uni-icons type="paperplane" size="18" color="#fff"></uni-icons>
					<text class="submit-text">提交反馈</text>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			feedbackTypes: [
				{ name: '功能异常', icon: 'bars' },
				{ name: '界面问题', icon: 'eye' },
				{ name: '使用建议', icon: 'chat' },
				{ name: '内容举报', icon: 'flag' },
				{ name: '其他问题', icon: 'help' }
			],
			selectedType: 0,
			description: '',
			contact: '',
			uploadedImages: [],
			isSubmitting: false
		}
	},
	computed: {
		canSubmit() {
			return this.description.trim().length > 0 && !this.isSubmitting
		}
	},
	methods: {
		selectType(index) {
			this.selectedType = index
		},
		chooseImage() {
			uni.chooseImage({
				count: 3 - this.uploadedImages.length,
				sizeType: ['compressed'],
				sourceType: ['album', 'camera'],
				success: (res) => {
					// 模拟上传成功
					this.uploadedImages = [...this.uploadedImages, ...res.tempFilePaths]
					uni.showToast({
						title: '图片添加成功',
						icon: 'success'
					})
				},
				fail: () => {
					uni.showToast({
						title: '选择图片失败',
						icon: 'error'
					})
				}
			})
		},
		deleteImage(index) {
			this.uploadedImages.splice(index, 1)
		},
		submitFeedback() {
			if (!this.canSubmit) return
			
			this.isSubmitting = true
			
			// 模拟提交过程
			uni.showLoading({
				title: '提交中...'
			})
			
			setTimeout(() => {
				uni.hideLoading()
				uni.showToast({
					title: '提交成功',
					icon: 'success'
				})
				
				// 重置表单
				this.resetForm()
				
				// 延迟返回上一页
				setTimeout(() => {
					uni.navigateBack()
				}, 1500)
				
				this.isSubmitting = false
			}, 2000)
		},
		resetForm() {
			this.selectedType = 0
			this.description = ''
			this.contact = ''
			this.uploadedImages = []
		}
	}
}
</script>

<style>
.feedback-container {
	min-height: 100vh;
	background-color: #f8f9fa;
}

.nav-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx 32rpx;
	background-color: #fff;
	border-bottom: 1px solid #e5e5e5;
	position: sticky;
	top: 0;
	z-index: 100;
}

.nav-left {
	padding: 10rpx;
}

.nav-title {
	font-size: 18px;
	font-weight: 600;
	color: #333;
}

.nav-right {
	width: 40rpx;
}

.main-content {
	padding: 32rpx;
}

.section {
	margin-bottom: 40rpx;
}

.section-title {
	font-size: 16px;
	font-weight: 600;
	color: #333;
	display: block;
	margin-bottom: 20rpx;
}

.type-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 20rpx;
}

.type-item {
	background-color: #fff;
	border-radius: 12rpx;
	padding: 24rpx 16rpx;
	text-align: center;
	border: 2px solid transparent;
	transition: all 0.3s ease;
}

.type-item.active {
	border-color: #8B4513;
	background-color: #fff8dc;
}

.type-text {
	font-size: 14px;
	color: #666;
	margin-top: 8rpx;
	display: block;
}

.type-item.active .type-text {
	color: #8B4513;
	font-weight: 600;
}

.input-card {
	background-color: #fff;
	border-radius: 12rpx;
	padding: 24rpx;
	position: relative;
}

.description-input {
	width: 100%;
	min-height: 200rpx;
	font-size: 14px;
	color: #333;
	line-height: 1.6;
	border: none;
	outline: none;
}

.contact-input {
	width: 100%;
	height: 80rpx;
	font-size: 14px;
	color: #333;
	border: none;
	outline: none;
}

.char-count {
	position: absolute;
	bottom: 16rpx;
	right: 24rpx;
	font-size: 12px;
	color: #999;
}

.upload-area {
	background-color: #fff;
	border-radius: 12rpx;
	padding: 24rpx;
}

.image-list {
	display: flex;
	flex-wrap: wrap;
	gap: 20rpx;
	margin-bottom: 16rpx;
}

.image-item {
	position: relative;
	width: 160rpx;
	height: 160rpx;
}

.uploaded-image {
	width: 100%;
	height: 100%;
	border-radius: 8rpx;
}

.delete-btn {
	position: absolute;
	top: -8rpx;
	right: -8rpx;
	width: 32rpx;
	height: 32rpx;
	background-color: rgba(0, 0, 0, 0.6);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
}

.upload-btn {
	width: 160rpx;
	height: 160rpx;
	border: 2px dashed #ddd;
	border-radius: 8rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	transition: all 0.3s ease;
}

.upload-btn:active {
	border-color: #8B4513;
	background-color: #fff8dc;
}

.upload-text {
	font-size: 12px;
	color: #8B4513;
	margin-top: 8rpx;
}

.upload-tip {
	font-size: 12px;
	color: #999;
}

.submit-section {
	margin-top: 60rpx;
	padding: 0 20rpx;
}

.submit-btn {
	width: 100%;
	height: 88rpx;
	background: linear-gradient(90deg, #8B4513 0%, #A0522D 100%);
	color: #fff;
	border-radius: 12rpx;
	border: none;
	font-size: 16px;
	font-weight: 600;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4rpx 16rpx rgba(139, 69, 19, 0.2);
	transition: all 0.3s ease;
}

.submit-btn.disabled {
	background: #ccc;
	box-shadow: none;
}

.submit-text {
	margin-left: 8rpx;
}
</style>
